
/**************************************************************************************************/
/*                                    All of those crazy verbs!                                   */
/**************************************************************************************************/

proc/HasSustenance(msg) if(istext(msg)) for(var/i = 1 to length(msg)) if(text2ascii(msg, i) > 32) return 1
proc/KillNewlines(msg)
	if(!istext(msg)) return msg
	. = ""
	var/len = length(msg)
	var/ch = 0
	for(var/i = 1; i <= len; i++)
		ch = text2ascii(msg, i)
		if(ch >= 0x20) . += ascii2text(ch)

client/verb
	Color()
		set hidden = 1
		src.Name_Color = pick("FF0000","00FF00","0000FF")
	Showcode(code as message)
		set hidden = 1
		if(!code || !istext(code) || !length(ckeyEx(code))) return 0;
		pastebin.Submit(src, code)

	Showtext(code as message)
		set hidden = 1
		if(!code || !istext(code) || !length(ckeyEx(code))) return 0;
		pastebin.Submit(src, code, 1)

	Say(msg as text)
		set
			hidden = 1
			name = ">"
		if(IsMuted())
			System_UserMessage(src, "You are currently muted.")
			return 0
		else
			setStatus("Available")
			if(HasSustenance(msg) && length(msg)<350)
				msg = KillNewlines(msg)
				for(var/client/C)
					if(!C.IsTelnet() && C.Colors) C << "<b>\[</b>[time2text(world.timeofday,"hh:mm:ss")]<b>\] <font color='#[Name_Color]'>[src.name]</font></b>: <font color='#[Text_Color]'>[html_encode(msg)]</font>"
					else C <<"<b>\[</b>[time2text(world.timeofday,"hh:mm:ss")]<b>\] [src.name]</b>: [html_encode(msg)]"

	Emote(msg as text)
		set
			hidden = 1
			name = "me"
		if(IsMuted())
			System_UserMessage(src, "You are currently muted.")
			return 0
		else
			setStatus("Available")
			if(HasSustenance(msg) && length(msg)<350)
				msg = KillNewlines(msg)
				for(var/client/C)
					if(!C.IsTelnet() && C.Colors) C << "<b>\[</b>[time2text(world.timeofday,"hh:mm:ss")]<b>\]</b> <font color='#[Name_Color]'>*[src.name] [html_encode(msg)]</font>"
					else C <<"<b>\[</b>[time2text(world.timeofday,"hh:mm:ss")]<b>\]</b> *[src.name]</b> [html_encode(msg)]"


client/Topic(href,href_list[])
	..()
	switch(href_list["action"])
		if("pastebin_view")
			src << browse("<html><head><script src=\"http://pastebin.com/embed_js.php?i=[href_list["id"]]\"></script></head><body></body></html>", "window=pastebin")


client/proc
	setStatus(type, status)
		src.Status -= src
		if(type == "Available")
			if(src.Status!=Available && !IsMuted())
				System_WorldMessage("[src.key] has returned!")
			src.Status = Available
			winset(src,"status_available","is-checked=true")

		if(type == "Away")
			if(src.Status == Available && !IsMuted())
				if(status)System_WorldMessage("[src.key] has gone away. ([status])")
				else System_WorldMessage("[src.key] has gone away.")
			src.Status = Away
			winset(src,"status_away","is-checked=true")

		if(type == "Busy")
			if(src.Status == Available && !IsMuted())
				if(status)System_WorldMessage("[src.key] is now busy. ([status])")
				else System_WorldMessage("[src.key] is now busy.")
			src.Status = Busy
			winset(src,"status_busy","is-checked=true")

		if(type == "Idle")
			if(src.Status == Available && !IsMuted())
				System_WorldMessage("[src.key] is now idle.")
			src.Status = Idle

		src.Status += src


client/verb
	afk(msg as text)
		set hidden = 1
		if(!msg) src.setStatus("Away","I have gone away.")
		else src.setStatus("Away",msg)